{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d44f2d28-3ad7-4537-a462-6f504744e055",
   "metadata": {},
   "source": [
    "Chapter 08\n",
    "# 函数输入有默认值\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "77087f0f-17b1-42a6-bc94-87744ac01c07",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自定义函数\n",
    "def greet(name, greeting='Hello'):\n",
    "    print(f\"{greeting}, {name}!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "60b98759-f679-4b11-977c-842c136d3cfb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, James!\n"
     ]
    }
   ],
   "source": [
    "# 使用默认的问候语调用函数\n",
    "greet('James')  # 输出 \"Hello, James!\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "131321ba-23d6-412d-9383-d421286e9f7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Good morning, James!\n"
     ]
    }
   ],
   "source": [
    "# 指定自定义的问候语调用函数\n",
    "greet('James', 'Good morning')  \n",
    "# 输出 \"Good morning, James!\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
